﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CLUBsInterpreter.AST;

namespace CLUBsInterpreter.ObjectTypes
{
	/**
	 * <summary>
	 * Describes a boolean object in the CLUBs environment.
	 * </summary>
	 **/
	class CLUBsBoolean : CLUBsObject
	{
		/**
		 * <summary>
		 * The actual boolean value.
		 * </summary>
		 **/
		public bool InternalBoolean = false;

		/**
		 * <summary>
		 * Default constructor creating a false boolean object.
		 * </summary>
		 **/
		public CLUBsBoolean()
		{
			// Set the object identifier type
			ObjectIdentifierType = AST.IdentifierType.Boolean;
		}

		/**
		 * <summary>
		 * Constructor taking initial boolean value.
		 * </summary>
		 **/
		public CLUBsBoolean(bool val)
			: this()
		{
			// Set the internal boolean value to the one specified
			InternalBoolean = val;
		}

		/**
		 * <see cref="CLUBsObject.CopyValueFromObject"/>
		 **/
		public override void CopyValueFromObject(CLUBsObject obj)
		{
            CLUBsBoolean boolObj = (CLUBsBoolean)obj;
            InternalBoolean = boolObj.InternalBoolean;
        }

		public override string ToString()
		{
			return InternalBoolean.ToString();
		}

		/**
		 * <summary>
		 * Implicit casting operator for easy casting to C# bool.
		 * </summary>
		 **/
		public static implicit operator bool(CLUBsBoolean cb)
		{
			// Return the internal boolean
			return cb.InternalBoolean;
		}

		/**
		 * <summary>
		 * Implicit casting operator for easy casting from C# bool.
		 * </summary>
		 **/
		public static implicit operator CLUBsBoolean(bool b)
		{
			// Return a new CLUBsBoolean with the initial value specified
			return new CLUBsBoolean(b);
		}

		public static CLUBsBoolean operator !(CLUBsBoolean obj1)
		{
			// Return CLUBsBoolean object with inverse value of obj1
			return (CLUBsBoolean)(!(bool)obj1);
		}
	}
}
